//
//  NEDProgressHUD.m
//  MoreCoin
//
//  Created by tete on 2018/6/14.
//  Copyright © 2018年 MoreCoin. All rights reserved.
//

#import "NEDHUD.h"
#import <SVProgressHUD/SVProgressHUD.h>
#import <NEDConstant/NEDConstant.h>
#import "UIView+Toast.h"
#import "NEDNotificationHUB.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <NEDStyle/UIColor+NEDStyle.h>


@interface NEDHUD : NSObject

+ (void)show;
+ (void)showWithStatus:(NSString *)text;
+ (void)showWithText:(NSString *)text;// 只显示文字

+ (void)dismiss;
+ (void)showErrorWithStatus:(NSString *)text;
+ (void)showSuccessWithStatus:(NSString *)text;

+ (void)showNotification:(NSString *)title detaileTitle:(NSString *)detail imageView:(UIImage *)imageView imageUrl:(NSURL *)url tapActionBlock:(void(^)(NEDNotificationHUB * passHUB))tapAcionBlock;


@end


void NEDHUDMsg(NSString * msg){
    [NEDHUD showWithText:msg];
}
void NEDHUDStatus(NSString * text){
    [NEDHUD showWithStatus:text];
}
void NEDHUDError(NSString * text){
    [NEDHUD showErrorWithStatus:text];
}
void NEDHUDSuccess(NSString * text){
    [NEDHUD showSuccessWithStatus:text];
}
void NEDHUDDismiss(void){
    [NEDHUD dismiss];
}
void NEDHUDShow(void){
    [NEDHUD show];
}
void NEDHUDNotificationShow(NSString * title,NSString * detailTitle,UIImage * imageView, NSURL * imageUrl,void(^tapActionBlock)(NEDNotificationHUB * passHUB)){
    [NEDHUD showNotification:title detaileTitle:detailTitle imageView:imageView imageUrl:imageUrl tapActionBlock:tapActionBlock];
}





@implementation NEDHUD

+(void)load{
    
    [SVProgressHUD appearance].defaultStyle = SVProgressHUDStyleLight;
    [SVProgressHUD appearance].backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [SVProgressHUD appearance].imageViewSize = CGSizeMake(28, 28);
    [SVProgressHUD appearance].foregroundColor = [UIColor ned_background];
    [SVProgressHUD appearance].font = [UIFont systemFontOfSize:17];
//    [SVProgressHUD appearance].offsetFromCenter = UIOffsetMake(0, 200);
}

+ (void)showWithText:(NSString *)text {
    if (IsNull(text)) {
        return;
    }
    [SVProgressHUD dismiss];
    
    CSToastStyle *style = [[CSToastStyle alloc]initWithDefaultStyle];
    style.messageFont = [UIFont systemFontOfSize:14];
    style.cornerRadius = 2.f;
    style.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
    style.horizontalPadding = Adapted(16);
    style.verticalPadding = Adapted(10);
    style.titleColor = [UIColor whiteColor];
    [CSToastManager setSharedStyle: style];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [[UIApplication sharedApplication].keyWindow makeToast:text duration:1.5 position:CSToastPositionCenter];
    });
}



+ (void)show{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
//    [SVProgressHUD setMinimumDismissTimeInterval:CGFLOAT_MAX];
//
//    [SVProgressHUD setImageViewSize:CGSizeMake(70, 70)];
//    [SVProgressHUD setBackgroundColor:[UIColor clearColor]];
//    [SVProgressHUD setInfoImage:[UIImage imageWithGIFNamed:@"loading"]];
//
//    [SVProgressHUD showInfoWithStatus:nil];
}



+ (void)showWithStatus:(NSString *)text{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    [SVProgressHUD showWithStatus:text];
    
//    [SVProgressHUD dismissWithDelay:1.5];
}

+ (void)dismiss{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
    [SVProgressHUD dismissWithDelay:0.03];
}

+ (void)showErrorWithStatus:(NSString *)text{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
    [SVProgressHUD showErrorWithStatus:text];
    [SVProgressHUD dismissWithDelay:1.5];
}

+ (void)showSuccessWithStatus:(NSString *)text{
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
    [SVProgressHUD showSuccessWithStatus:text];
    [SVProgressHUD dismissWithDelay:1.5];
}
+ (void)showNotification:(NSString *)title detaileTitle:(NSString *)detail imageView:(UIImage *)imageView imageUrl:(NSURL *)url tapActionBlock:(void(^)(NEDNotificationHUB * passHUB))tapAcionBlock {
    NEDNotificationHUB * yhBub = [NEDNotificationHUB new];
    yhBub.textLabel.text = title;
    yhBub.detailTextLabel.text = detail;
    [yhBub.imageView sd_setImageWithURL:url placeholderImage:imageView];
    yhBub.tapActionBlock = tapAcionBlock;
    [yhBub show];
}

@end
